package net.hsxin.test.activiti.service;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.springframework.stereotype.Service;

@Service
public class ProcessService
{
	@Resource
	private RuntimeService runtimeService;
	
	@Resource
	private RepositoryService repositoryService; 

	public RepositoryService getRepositoryService()
	{
		return repositoryService;
	}

	public void setRepositoryService(RepositoryService repositoryService)
	{
		this.repositoryService = repositoryService;
	}

	public RuntimeService getRuntimeService()
	{
		return runtimeService;
	}

	public void setRuntimeService(RuntimeService runtimeService)
	{
		this.runtimeService = runtimeService;
	}
	
	public List<ProcessInstance> getCreatedProcesses()
	{
		ProcessInstanceQuery query = this.runtimeService.createProcessInstanceQuery();
		return query.list();
	}
	
	public List<ProcessDefinition> getDeployProcesses()
	{
		return this.repositoryService.createProcessDefinitionQuery().list();
	}
	
	public ProcessInstance createProcess(String processKey)
	{
		return this.runtimeService.startProcessInstanceByKey(processKey);
	}
}
